/*
 *  Copyright (C) 2011  social-tourist.org
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.socialtourist.web.client.widgets;

import org.socialtourist.web.client.ContentContainer;
import org.socialtourist.web.client.ContentContainer.sections;


import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;

import static org.socialtourist.web.client.ContentContainer.sections.*;


public class MenuWidget extends SocialTouristContent {

	Command cmd = new Command() {
		public void execute() {
			Window.alert("Menu item have been selected");
		}
	};
	private class GotoCommand implements Command 
	{
		private sections target;

		public GotoCommand(sections target) {
			this.target = target;
		}
		
		public void execute() {
			getContainer().goTo(target);
			
		}
	};
	
	private MenuBar projects;
	private MenuBar admin;
	private MenuItem internItem;
	private MenuBar menu;
	private MenuItem adminItem;

	public MenuWidget(ContentContainer container) {
		super(container);
		
		projects = new MenuBar(true);
		projects.addItem("Kindergarten Chile", cmd);
		projects.addItem("Waisenhaus Kaokoland", cmd);
		projects.addItem("Bauernhof India", cmd);
		projects.addItem("Kindergarten Mongolia", cmd);

		menu = new MenuBar();
		menu.addItem("Projekte", projects);
		menu.addItem("&uuml;ber uns", true, cmd);
		menu.addItem("Kontakt", cmd);
		
		internItem = new MenuItem("Intern", new GotoCommand(login));
		menu.addItem(internItem);
		
		admin = new MenuBar(true);
		adminItem = new MenuItem("Admin", admin);
		admin.addItem("Add project", new GotoCommand(add_project));
		admin.addItem("Edit project", new GotoCommand(edit_project));
		admin.addItem("Edit need", new GotoCommand(edit_needs));
		admin.addItem("Upload pictures", new GotoCommand(upload_picture));
		admin.addItem("Logout", new GotoCommand(logout));
		
		
		
		initWidget(menu);
	}

	public void enableAdminEntries() 
	{
		menu.removeItem(internItem);
		menu.addItem(adminItem);
	}
	public void disableAdminEntries() 
	{
		menu.removeItem(adminItem);
		menu.addItem(internItem);
	}


}
